package backend;

import java.util.ArrayList;

public class RegexPlugin extends Plugin {

    private String regex;

    public RegexPlugin(String name, ArrayList<Server> serverList, String command) {
        super(name, serverList);
        this.regex = command;//.replaceFirst("grep ", "");
    }

    @Override
    public String getCommandStr() {
        System.out.println("grep -neH '" + getRegex() + "'");
        return "grep -n -H '" + getRegex() + "'";
    }

    @Override
    public boolean check() {
        for (Server server : serverList) {
            for (String log : server.getLogs()) {
                String grepCommand = getCommandStr() + " " + log;
                String command = "ssh " + server.getIp() + " \"" + grepCommand + "\"";
                runCommand(command);
            }

        }
        return true;
    }

    /**
     * @return the regex
     */
    public String getRegex() {
        return regex;
    }

    /**
     * @param regex the regex to set
     */
    public void setRegex(String regex) {
        this.regex = regex;
    }
}
